package cn.zz.camerasdk.views;

/**
 * author: zhu on 2017/7/7 16:51
 * email: mackkill@gmail.com
 */

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class CameraGrid extends View {
    private int topBannerWidth;
    private Paint mPaint;
    private boolean showGrid;

    public CameraGrid(Context context) {
        this(context, (AttributeSet)null);
    }

    public CameraGrid(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.topBannerWidth = 0;
        this.showGrid = true;
        this.init();
    }

    private void init() {
        this.mPaint = new Paint();
        this.mPaint.setColor(-1);
        this.mPaint.setAlpha(120);
        this.mPaint.setStrokeWidth(1.0F);
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
        int height = this.getHeight();
        if(width < height) {
            this.topBannerWidth = height - width;
        }

        if(this.showGrid) {
            canvas.drawLine((float)(width / 3), 0.0F, (float)(width / 3), (float)height, this.mPaint);
            canvas.drawLine((float)(width * 2 / 3), 0.0F, (float)(width * 2 / 3), (float)height, this.mPaint);
            canvas.drawLine(0.0F, (float)(height / 3), (float)width, (float)(height / 3), this.mPaint);
            canvas.drawLine(0.0F, (float)(height * 2 / 3), (float)width, (float)(height * 2 / 3), this.mPaint);
        }

    }

    public boolean isShowGrid() {
        return this.showGrid;
    }

    public void setShowGrid(boolean showGrid) {
        this.showGrid = showGrid;
    }

    public int getTopWidth() {
        return this.topBannerWidth;
    }
}
